<template>
  <div class="login-page">
    <el-form
      label-position="right"
      label-width="100px"
      :model="loginForm"
      style="max-width: 600px"
    >
      <el-form-item label="用户名" prop="username">
        <el-input v-model="loginForm.username"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input v-model="loginForm.password" type="password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup lang="ts">
import { reactive } from 'vue';
import { loginApi } from '@/api/login';
import { useUserInfoStore } from '@/store/index';

const { setToken } = useUserInfoStore()

const loginForm = reactive({
  username: '',
  password: ''
})

const onSubmit = async () => {
  // console.log(loginForm)
  const res = await loginApi(loginForm)
  setToken(res.data.token)

}
</script>

<style lang="scss" scoped></style>
